package usually;

import java.util.HashMap;
import java.util.Map;

//1695. 删除子数组的最大得分
public class Num1695_maximumUniqueSubarray {
    /**
     * 滑动窗口
     * @param nums
     * @return
     */
    public int maximumUniqueSubarray(int[] nums) {

        int l = 0,r = 0,res = nums[0],sum = nums[0] ;
        int []mark = new int[100005];//标记数组，来判断nums[r] 是否存在
        mark[nums[0]] = 1;
        for (int i = 0; i < nums.length; i++) {
            r++;//右指针后移
            while (mark[nums[r]] == 0){
                //找到去除左边与其相等的值
                mark[nums[l] ] = 0;
                sum -= nums[l];
                l++;
            }
            //此时不存在重复值
            sum +=nums[r];
            mark[nums[r]] = 1;
            res = Math.max(res , sum);
        }
        return res;
    }
}
